
import { onLink } from "../hooks/useRoute";
import { oneStore } from "../api/store";

function useSAcan() {
  return new Promise((resolve, reject) => {
    uni.scanCode({
      scanType: "barCode",
      success(res) {
        oneStore({ code: res.result }).then((result) => {
          if (result.data) {
            onLink(`/pages/edit/index?id=${result.data.id}`);
          } else {
            onLink(`/pages/edit/index?code=${res.result}`);
          }
          resolve();
        });
      },
      fail(err) {
        reject(err); // 扫码失败
      },
    });
  });
}

export default useSAcan;
